{% extends "!layout.html" %}
{%- block extrahead %}
<meta name="sourcename" content="{{ sourcename }}" />
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-124060019-2"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-124060019-2');
</script>
<script>
    function getCookie(cname) {
      var name = cname + "=";
      var decodedCookie = decodeURIComponent(document.cookie);
      var ca = decodedCookie.split(';');
      for(var i = 0; i <ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') {
          c = c.substring(1);
        }
        if (c.indexOf(name) == 0) {
          return c.substring(name.length, c.length);
        }
      }
      return "";
    }
    
    var head = document.getElementsByTagName('HEAD')[0];  
    var link = document.createElement('link'); 
    link.rel = 'stylesheet';  
    link.type = 'text/css'; 
    var theme = getCookie('user_theme');
    if (theme == "dark") {
        link.href = '/_static/theme-dark.css';
    } else {
        link.href = '/_static/theme-light.css';
    }
    head.appendChild(link);
</script>
{% if "index" in sourcename %}
  <script type="text/javascript" src="./_static/old-guide-redirect.js"></script>
{% endif %}
{% if "switch-theme" in sourcename %}
  <script>
    function setCookie(cname, cvalue, exdays) {
      var d = new Date();
      d.setTime(d.getTime() + (exdays*24*60*60*1000));
      var expires = "expires="+ d.toUTCString();
      document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
    }
    
    var theme = getCookie('user_theme');
    if (theme == 'dark') {
        setCookie('user_theme', 'light', 365);
    } else {
        setCookie('user_theme', 'dark', 365);
    }
    
    window.location.replace(document.referrer);
  </script>
{% endif %}
{% endblock %}